#include<bits/stdc++.h>
using namespace std;
int T,n,a[200100],t[2],ans;
inline void dfs(int k,int s)
{
    int tmp;
    if(k>n)
    {
        ans=max(ans,s);
        return;
    }
    tmp=t[0];
    if(a[k]==tmp)s+=a[k];
    else t[0]=a[k];
    dfs(k+1,s);
    if(a[k]==tmp)s-=a[k];
    t[0]=tmp;
    tmp=t[1];
    if(a[k]==tmp)s+=a[k];
    else t[1]=a[k];
    dfs(k+1,s);
    if(a[k]==tmp)s-=a[k];
    t[1]=tmp;
}
int main()
{
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    cin>>T;
    while(T--)
    {
        cin>>n;
        ans=0;
        for(int i=1;i<=n;i++)
        {
            cin>>a[i];
        }
        t[0]=a[1];
        t[1]=0;
        dfs(2,0);
        cout<<ans<<"\n";
    }
    return 0;
}
